﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tisonet.Dobrak.Client.WP8.Services;
using Tisonet.Dobrak.Domain.Models;

namespace Tisonet.Dobrak.Client.WP8.ViewModels
{
    public class MovieViewModel : ViewModelBase
    {
        private readonly IMoviesService _service;
        private string _movieName;
        private string _movieYear;

        public MovieViewModel(IMoviesService service)
        {
            _service = service;
        }

        public string MovieName
        {
            get { return _movieName; }
            private set
            {
                if (_movieName != value)
                {
                    _movieName = value;
                    NotifyPropertyChanged("MovieName");
                }
            }
        }

        public string MovieYear
        {
            get { return _movieYear; }
            private set
            {
                if (_movieYear != value)
                {
                    _movieYear = value;
                    NotifyPropertyChanged("MovieName");
                }
       
            }
        }

        public bool IsDataLoaded { get; private set; }

        public void LoadData(string id)
        {
            _service.DownloadsMovieAsync(id, ShowMovie);
        }

        private void ShowMovie(Movie movie)
        {
            if (movie != null)
            {
                MovieName = movie.Name;
                MovieYear = movie.Year;
            }

            IsDataLoaded = true;
        }
    }
}
